home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu374.dms / pu374.adf / AGAtest / gtest.c < prev    next >
C/C++ Source or Header  |  1992-12-06  |  4KB  |  135 lines

  1. /* Some SAS/C 6.0 code to show all 2^24 colors available with HAM8
  2.    on a sequence of successive screens without ever changing the
  3.    64 base color registers after the initial setup.
  4.  
  5.    This code is PD.  Donated to the public domain by the author,
  6.    Loren J. Rittle <rittle@comm.mot.com>.  Have fun with it, but
  7.    please don't claim this work as your own.  As it is PD, please
  8.    feel free to take pieces to your own projects.
  9.  
  10.    Loren J. Rittle
  11.    Sun Nov  8 09:52:11 1992
  12. */
  13.  
  14. /* To allow this to compile with the STRICT ANSI WARNING=ALL options: */
  15. #pragma msg 148 ignore
  16. #pragma msg 149 ignore push
  17. #pragma msg 61 ignore push
  18. #include <proto/dos.h>
  19. #include <proto/exec.h>
  20. #include <proto/intuition.h>
  21. #include <proto/graphics.h>
  22. #pragma msg 149 pop
  23. #pragma msg 61 pop
  24.  
  25. /* Thanks to Chris Green: */
  26. LoadRGB32 (struct ViewPort *, unsigned long *table);
  27. #pragma libcall GfxBase LoadRGB32 372 9802
  28.  
  29. /* Let's hope that more entry points are revealed on UseNet to tide us
  30.    over until the real includes are available...
  31.    For example, I'd like the pragma info on the system calls that allow
  32.    me to do double bufferred animation under the OS... :-) */
  33.  
  34. /* Prototype to allow this to compile with WARNING=ALL option: */
  35. int main (int argc, char *argv[]);
  36.  
  37. int main (int argc, char *argv[])
  38. {
  39.   /* Open a HAM8 screen: */
  40.   UWORD t[] = {0xffff};
  41.   struct Screen *s = OpenScreenTags (NULL, SA_Pens, t, SA_SysFont, 1,
  42.         SA_Title, "AGA HAM8 mode test by Loren J. Rittle",
  43.         SA_DisplayID, HIRES_KEY | HAM_KEY, SA_Depth, 8, TAG_DONE);
  44.  
  45.   /* We don't need to look at the command line arguments that get
  46.      stacked on Input ().  Flush () 'em: */
  47.   Flush (Input ());
  48.  
  49.   if (s)
  50.     {
  51.       /* Open a window on the HAM8 screen: */
  52.       struct Window *w = OpenWindowTags (NULL, WA_CustomScreen, s,
  53.         WA_Borderless, 1, TAG_DONE);
  54.  
  55.       if (w)
  56.     {
  57.       /* Set up 64 base color registers for HAM8 screen: */
  58.       int i, j, k;
  59.       static unsigned long ct[1 + 64 * 3 + 1];
  60.  
  61.       ct[0] = (64 << 16) + 0;
  62.       for (i = 0; i < 4; i++)
  63.         for (j = 0; j < 4; j++)
  64.           for (k = 0; k < 4; k++)
  65.         {
  66.           ct[(k * 16 + j * 4 + i) * 3 + 1] = i << 24;
  67.           ct[(k * 16 + j * 4 + i) * 3 + 2] = j << 24;
  68.           ct[(k * 16 + j * 4 + i) * 3 + 3] = k << 24;
  69.         }
  70.       LoadRGB32 (&(s->ViewPort), ct);
  71.  
  72.       /* We will never change the base color registers again,
  73.          after this point, but yet, we can display all 2^24
  74.          colors available on a HAM8 screen. :-) */
  75.  
  76.       {
  77.         int r, g, b;
  78.  
  79.         /* Set up static pixels on the screen: */
  80.         for (j = 0; j < 4; j++)
  81.           for (k = 0; k < 4; k++)
  82.         for (i = 0; i < 4; i++)
  83.           {
  84.                 SetAPen (w->RPort, j * 16 + k * 4 + i);
  85.                 WritePixel (w->RPort, 97 + j * 100, 100 + i + k * 20);
  86.                 SetAPen (w->RPort, 0xc0 + 0);
  87.                 WritePixel (w->RPort, 98 + j * 100, 100 + i + k * 20);
  88.                 SetAPen (w->RPort, 0x40 + 0);
  89.                 WritePixel (w->RPort, 99 + j * 100, 100 + i + k * 20);
  90.                 for (r = 0; r < 64; r++)
  91.               {
  92.                 SetAPen (w->RPort, 0x80 + r);
  93.                 WritePixel (w->RPort, 100 + r + j * 100, 100 + i + k * 20);
  94.               }
  95.               }
  96.  
  97.         /* Loop over all high order green and blue combos: */
  98.         for (b = 0; b < 64; b++)
  99.           for (g = 0; g < 64; g++)
  100.         {
  101.           if (CheckSignal (SIGBREAKF_CTRL_C))
  102.             goto out;
  103.  
  104.           WaitTOF ();
  105.           WaitTOF ();
  106.  
  107.           /* Change dynamic pixels on screen: */
  108.           for (j = 0; j < 4; j++)
  109.             for (k = 0; k < 4; k++)
  110.               for (i = 0; i < 4; i++)
  111.                 {
  112.                   SetAPen (w->RPort, 0xc0 + g);
  113.                   WritePixel (w->RPort, 98 + j * 100, 100 + i + k * 20);
  114.                   SetAPen (w->RPort, 0x40 + b);
  115.                   WritePixel (w->RPort, 99 + j * 100, 100 + i + k * 20);
  116.                 }
  117.         }
  118.       }
  119.  
  120.       /* Done, we have now seen all 2^24 colors without ever
  121.          changing the base registers. */
  122.       FGetC (Input ());
  123.     out:
  124.       CloseWindow (w);
  125.     }
  126.       else
  127.     PutStr ("gtest: error opening window\n");
  128.  
  129.       CloseScreen (s);
  130.     }
  131.   else
  132.     PutStr ("gtest: error opening screen\n");
  133.   return (0);
  134. }
  135.